<?php
namespace Admin\Controller;
use Think\Controller;
class videoController extends Controller {

    //显示用户列表方法
    public function videolistJson(){
       
       $use= $this->users=M('video')->select();
   echo json_encode($use);
      } 
  
    public function videoList() {
        $videoModel = M('video');
        $videoList = $videoModel -> select();

        $this -> assign('videoList',$videoList);
        $this -> display();
    }
   public function doAddvideo() {
        $videoModel = M('video');
        //上传图片
        if ($_FILES['videopic']['error'] == 0) {
            $imageInfo = $this->upload();
            $pname = $imageInfo['videopic']['savename'];
        } else {
            $pname = "default.jpg";
        }

        $addvideoData['videoid'] = NULL;
        $addvideoData['videoname'] = I('post.videoname');
        $addvideoData['address'] = I('post.address');
        $addvideoData['videodate'] = date('y-m-d H:m:s');
        $addvideoData['videotext'] = I('post.videotext');
    

        $res = $videoModel -> add($addvideoData);

        if ($res) {
            $this -> success("添加成功!");
        } else {
            $this -> error("添加失败!");
        }
    }
       public function updatevideo($id){
        $videoModel = M('video');
        $videoData['videoid'] = $id;
        $res = $videoModel -> where($videoData) -> find();
        $this -> assign('videoInfo', $res);
        $this -> display();
    }
    public function doupdatevideo() {
        $videoModel = M('video');

        $updatevideoData['videoid'] = I('post.videoid');
        $updatevideoData['videoname'] = I('post.videoname');
        $updatevideoData['address'] = I('post.address');
        $updatevideoData['videotel'] = I('post.videotel');
        $updatevideoData['videodate'] = date('y-m-d H:m:s');
        $updatevideoData['videotext'] = I('post.videotext');
    

        $res = $videoModel -> save($updatevideoData);

        if ($res) {
            $this -> success("修改成功!",U('video/videoList'));
        } else {
            $this -> error("修改失败!");
        }
    }
       public function delvideo($id){
      $res= M("video") -> where("videoid = '$id'") -> delete();
       if ($res) {
            $this -> success("删除成功!",U('video/videoList'));
        } else {
            $this -> error("修改失败!");
        }
    }

    

    //  public function index(){
    //     $share = M('share');
    //     //用户名条件搜索
    //     if(!empty($_GET['name'])){
    //       $where['name'] = array('like','%'.$_GET['name'].'%');
    //     }
    //     $total=$user->where($where)->count();
        
    //     //实例化分页类
    //     $page=new \Think\Page($total,5);
    //     $this->assign('show',$page->show());
    //     $data=$user->where($where)->page(I('get.p',1),5)->select();
    //     $this->assign('data',$data);
    //     $this->display();
    // }
public function Upload()
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Public/upload/video/'; // 设置附件上传根目录
      //  $upload->savePath  =   'Banner/'; // 设置附件上传（子）目录
        $upload->autoSub = false;
        $info = $upload->upload(); // 上传文件

        if (!$info) {
            $this->error($upload->getError());
        } else {
            return $info;
        }
    }
}
